<template>
  <div>
    <el-dialog
      title="设备添加"
      :visible.sync="dialogVisible"
      center
      width="50%"
      :before-close="handleClose">
      <el-card>
        <el-form :model="groupAdd" status-icon :rules="rules" ref="house" label-width="100px">
          <el-form-item label="设备编码" prop="fnumber" required>
            <el-input v-model="group.fnumber" autocomplete="off"></el-input>
          </el-form-item>
          <el-form-item label="设备名称" prop="fname" required>
            <el-input v-model="group.fname" autocomplete="off"></el-input>
          </el-form-item>
          <el-form-item label="上级分组" prop="fparentName">
            <el-input v-model="groupAdd.fname" autocomplete="off" disabled></el-input>
          </el-form-item>
        </el-form>
      </el-card>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm()">提交</el-button>
        <el-button @click="handleClose()">关闭</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
import Group from "@/api/psyManage/Group";

export default {
  name: "add_tree",
  props:{
    groupAdd:''
  },
  data(){
    return{
      dialogVisible:true,
      group:{
        fnumber:'',
        fname:'',
        fparentid: this.groupAdd.nodeId,
        fparentName:this.groupAdd.fname
      },
      rules:{
        fnumber:[{required:true,message:'分组编码不能为空',trigger:'blur'}],
        fname:[{required:true,message:'分组名称不能为空',trigger:'blur'}],
      }
    }

  },
  created() {
  },
  methods:{
    handleClose(){
      this.$emit("close", {name: "treeAdd", isRefreshTree: false});
    },
    submitForm(){
      this.$refs['house'].validate((valid) => {
        if (valid) {
          const loading = this._loading();
          const api = new Group();
          this.group.fParentid=this.groupAdd.nodeId;
          api.add(this.group).then(res => {
            loading.close();
            this.$tie.showSuccess("提示","操作成功")
            this.$emit("close", {name: 'treeAdd',  isRefreshTree: true});
          }).catch(e => loading.close())
        }
        return false;
      })
    },
    //加载提示
    _loading() {
      return this.$loading({
        lock: true,
        text: '请耐心等待.....',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.7)'
      })
    }
  }
}
</script>

<style scoped>

</style>
